import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    redirect: '/window-manager'
  },
  {
    path: '/window-manager',
    name: 'WindowManager',
    component: () => import('@/components/views/WindowManager.vue'),
    meta: { title: '窗口管理' }
  },
  {
    path: '/environment',
    name: 'Environment',
    component: () => import('@/components/views/Environment.vue'),
    meta: { title: '环境创建' }
  },
  {
    path: '/layout',
    name: 'Layout',
    component: () => import('@/components/views/Layout.vue'),
    meta: { title: '布局管理' }
  },
  {
    path: '/sync',
    name: 'Sync',
    component: () => import('@/components/views/Sync.vue'),
    meta: { title: '同步控制' }
  },
  {
    path: '/batch-actions',
    name: 'BatchActions',
    component: () => import('@/components/views/BatchActions.vue'),
    meta: { title: '批量操作' }
  },
  {
    path: '/settings',
    name: 'Settings',
    component: () => import('@/components/views/Settings.vue'),
    meta: { title: '设置' }
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 路由前置守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  document.title = to.meta.title ? `${to.meta.title} - Chrome Manager` : 'Chrome Manager'
  next()
})

export default router